<?php
/**
 * @see Zend_Filter_Interface
 */
require_once 'Zend/Filter/Interface.php';

/**
 * @see Zend_Date
 */
require_once 'Zend/Date.php';

/**
 * Wufoo_Form
 *
 * @category   Wufoo
 * @package    Wufoo_Filter
 * @copyright  Copyright (c) 2009-2010 Eyeflow Internet Marketing. (http://www.eyeflow.com)
 * @author     Sergei Izvorean
 */
class Wufoo_Filter_Date implements Zend_Filter_Interface
{
    /**
     * Convert MM/DD/YYYY to Wufoo YYYYMMDD format
     *
     * @uses Zend_Date
     * @param string $value
     * @return string Date in form YYYYMMDD
     */
    public function filter($value)
    {
        if (empty($value))
            return $value;

        try {
            $date = new Zend_Date($value, null, 'en_US');

            return $date->toString(Zend_Date::YEAR.Zend_Date::MONTH.Zend_Date::DAY);
        } catch (Exception $e) {
            return $value;
        }
    }
}